export default {
  namespaced: true,
  state: {
    products: [],
  },
  getters: {},
  mutations: {
    SET_PRODUCT(state, payload) {
      state.products = payload;
    },
    DECREASE_PRO(payload) {
      // 需要知道让哪一条的数据库存减少
      // let target = state.products.find(item => item.id === payload.id)
      // if (target) {
      //     payload.inventory--
      // }
      payload.inventory--;
    },
    INCREASE_PRO(state, payload) {
      let target = state.products.find((item) => item.id === payload.id);
      if (target) {
        target.inventory++;
      }
      // payload.inventory++
      console.log(11);
    },
  },
  actions: {
    async FETCH_PRODUCT(context) {
      let res = await fetch("http://chst.vip/data/index.json").then((body) =>
        body.json()
      );
      console.log(res.data);
      context.commit("SET_PRODUCT", res.data);
    },
  },
  modules: {},
};
